package de.tabuma.shopping.view;

import de.tabuma.lib.tabumaview;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import de.tabuma.shopping.*;

/**
 *
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.4.1 $
 * @since $Date: 2010/01/13 10:22:52 $
 */
public class view extends tabumaview {

    private static Logger log =  Logger.getLogger(view.class.getName());

    String orderNav;

    de.tabuma.shopping.controller.controller controller;

    public view(String servlet, Hashtable parameter, String orderNav, de.tabuma.shopping.controller.controller controller) {
        super(servlet, parameter);
        this.orderNav = orderNav;
        this.controller = controller;
    }
    
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out)  {
        try {

            out.println("<div class=\"contentHeader\">"+constants.getValueFromProperties("orders.header")+"</div>");
            
            Integer nav = (Integer) request.getAttribute(orderNav);
            if(nav==null) {
                nav = constants.ORDERNAV_NULL;
            }

            switch(nav) {
                case constants.ORDERNAV_NULL:
                    overview orderOverview = new overview(this.getServlet(), this.getParameter(), orderNav);
                    log.fine("Giving focus OrderOverview.");
                    orderOverview.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_DESCRIPTION:
                    description orderDescription = new description(this.getServlet(), this.getParameter(), orderNav);
                    log.fine("Giving focus OrderDescription.");
                    orderDescription.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_PACKAGE:
                    licensePackageOverview orderLicensePackege = new licensePackageOverview(this.getServlet(), this.getParameter(), orderNav, controller);
                    log.fine("Giving focus OrderLicensePackage.");
                    orderLicensePackege.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_DETAILS:
                    details orderDetails = new details(this.getServlet(), this.getParameter(), this.orderNav);
                    log.fine("Giving focus OrderDetails.");
                    orderDetails.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_LICENSEAGREEMENT:
                    licenseAgreement orderLicenseAgreement = new licenseAgreement(this.getServlet(), this.getParameter(), orderNav);
                    log.fine("Giving focus OrderLicenseAgreement.");
                    orderLicenseAgreement.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_ERRORPAYMENT:
                    errorPaymentProcess errorPaymentProcess = new errorPaymentProcess(this.getServlet(), this.getParameter());
                    log.fine("Giving focus ErrorPaymentProcess.");
                    errorPaymentProcess.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_VERIFICATIONPAYMENT:
                    verificationOfPayment verificationOfPayment = new verificationOfPayment(this.getServlet(), this.getParameter(), orderNav);
                    log.fine("Giving focus VerificationOfPayment.");
                    verificationOfPayment.processRequest(context, request, response, out);
                    break;
                case constants.ORDERNAV_FORWARDPAYPAL:
                    forwardToPayPal forwardToPayPal = new forwardToPayPal(this.getServlet(), this.getParameter(), orderNav);
                    log.fine("Giving focus ForwardToPayPal.");
                    forwardToPayPal.processRequest(context, request, response, out);
                    break;
            }

        }
        catch(Exception e) {
            log.warning(e.getMessage());
        }
    } 

}
